import urllib
import os
import logging
import time
import string

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db


os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.ext.webapp import template    

class MainHandler(webapp.RequestHandler):
    def get(self):
        template_values = {}
        path = os.path.join(os.path.dirname(__file__), 'home.html')
        self.response.out.write(template.render(path, template_values))

class EncodeHandler(webapp.RequestHandler):
    def get(self):
        inputText = 'Write your text here'     
        output = ''
        template_values = {'inputText' : inputText, 'output' : output} 
        path = os.path.join(os.path.dirname(__file__), 'encode.html')
        self.response.out.write(template.render(path, template_values))
    def post(self):
        inputText = self.request.get('input')      
        import test
        output = test.encode(inputText)
        template_values = {'inputText' : inputText, 'output' : output} 
        path = os.path.join(os.path.dirname(__file__), 'encode.html')
        self.response.out.write(template.render(path, template_values))

class DecodeHandler(webapp.RequestHandler):
    def get(self):
        inputText = 'Write your encrypted text here'
        output = ''
        template_values = {'inputText' : inputText}
        path = os.path.join(os.path.dirname(__file__), 'decode.html')
        self.response.out.write(template.render(path, template_values))
    def post(self):
        inputText = self.request.get('input')      
        import test
        output = test.decode(inputText)
        template_values = {'inputText' : inputText, 'output' : output} 
        path = os.path.join(os.path.dirname(__file__), 'decode.html')
        self.response.out.write(template.render(path, template_values))

class CreateHandler(webapp.RequestHandler):
    def get(self):
        template_values = {}
        path = os.path.join(os.path.dirname(__file__), 'create.html')
        self.response.out.write(template.render(path, template_values))


class rot13Handler(webapp.RequestHandler):
    template_values = {}
 
    def decrypt_rot13(mess):
        import test
        return test.decode(mess)

    def encrypt_rot13(mess):
        import test
        return test.encode(mess)



def main():
  application = webapp.WSGIApplication([('/encode.*', EncodeHandler),
                                        ('/decode.*', DecodeHandler),
                                        ('/create.*', CreateHandler),
                                        ('/.*', MainHandler)],
                                       debug=True)
  run_wsgi_app(application)

if __name__ == '__main__':
  main()

